package com.orange.studio.dbk.adapters;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.orange.studio.dbk.R;
import com.orange.studio.dbk.fragments.FavioritesFragment;
import com.orange.studio.dbk.fragments.HomeFragment;
import com.orange.studio.dbk.fragments.TestFragment;
import com.viewpagerindicator.IconPagerAdapter;

public class MainFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter{
    protected static final String[] CONTENT = new String[] { "This", "Is", "A"};
    private static final int[] ICONS = new int[] {
        R.drawable.ic_launcher,
        R.drawable.ic_launcher,
        R.drawable.ic_launcher
    };
    
    private int mCount = CONTENT.length;
    private Context context;
    private Fragment mCurrentFragment;
    
    public MainFragmentAdapter(Context _context,FragmentManager fm) {
        super(fm);
        context=_context;
    }

    @Override
    public Fragment getItem(int position) {
    	//return Fragment.instantiate(context, HomeFragment.class.getName());
    	switch (position) {	
    	case 0:
    		return Fragment.instantiate(context, HomeFragment.class.getName());
    	case 2:
    		return Fragment.instantiate(context, FavioritesFragment.class.getName());
		default:
			return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
		}
        
    }

    @Override
    public int getCount() {
        return mCount;
    }

    @Override
    public CharSequence getPageTitle(int position) {
    	
      return MainFragmentAdapter.CONTENT[position % CONTENT.length];
    }
    public void setCount(int count) {
        if (count > 0 && count <= 10) {
            mCount = count;
            notifyDataSetChanged();
        }
    }
    @Override
    public int getIconResId(int index) {
      return ICONS[index % ICONS.length];
    }
    

    public Fragment getCurrentFragment() {
        return mCurrentFragment;
    }
    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        if (getCurrentFragment() != object) {
            mCurrentFragment = ((Fragment) object);
        }
        super.setPrimaryItem(container, position, object);
    }
}